package com.example.artwindow.controller;

import com.example.artwindow.domain.dto.MovieUploadDTO;
import com.example.artwindow.domain.dto.PageMovieByUserDTO;
import com.example.artwindow.domain.dto.PageMovieDTO;
import com.example.artwindow.domain.vo.MovieDetailsVO;
import com.example.artwindow.domain.vo.MovieVO;
import com.example.artwindow.result.ListResult;
import com.example.artwindow.result.Result;
import com.example.artwindow.service.MovieService;
import com.example.artwindow.tool.QiNiuOSTool;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/movie")
@Tag(name="电影相关接口")
@Slf4j
@RequiredArgsConstructor
public class MovieController {

	private final MovieService movieService;
	@Operation(summary = "查询电影")
	@GetMapping("/pageMovie")
	public Result<ListResult<MovieVO>> pageMovie(PageMovieDTO pageMovieDTO){
		return movieService.pageMovie(pageMovieDTO);
	}

	@PreAuthorize("hasAuthority('movie:upload')")
	@Operation(summary = "上传电影")
	@PostMapping(value = "/uploadMovie",consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
	public Result<?> uploadMovie(MovieUploadDTO movieUpLoadDTO ,
	                             @RequestPart(value = "movieCover",required = false) MultipartFile movieCover) throws IOException {
		return movieService.upLoadMovie(movieUpLoadDTO,movieCover);
	}

	@Operation(summary = "根据id查询剧情")
	@GetMapping("/{id}")
	public Result<MovieDetailsVO> selectPlotById(@PathVariable Long id){
		return movieService.selectPlotById(id);
	}

}
